package com.xyy.saas.payment.callback.core.job;

import com.alibaba.fastjson.JSON;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.xyy.elasticjob.client.annotation.ElasticJobConf;
import com.xyy.saas.payment.payment.core.service.PinganCreditReconcileService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author wangzeqi
 * 平安贷交易核对
 */
@Slf4j
@ElasticJobConf(name = "com.xyy.saas.payment.callback.core.job.PinganCreditVerifyTransactionJob", cron = "0 0 23 * * ?")
@RequiredArgsConstructor
public class PinganCreditVerifyTransactionJob implements SimpleJob {

    private final PinganCreditReconcileService pinganCreditReconcileService;

    @Override
    public void execute(ShardingContext shardingContext) {
        long begin = System.currentTimeMillis();
        log.info("PinganCreditPayReconcileJob.execute started. shardingContext:{}", JSON.toJSONString(shardingContext));

        try {
            pinganCreditReconcileService.verifyCreditPaySettle();
        } catch (Exception e) {
            log.error("PinganCreditPayReconcileJob.verifyCreditPaySettle error", e);
        }

        try {
            pinganCreditReconcileService.verifyCreditPayRefund();
        } catch (Exception e) {
            log.error("PinganCreditPayReconcileJob.verifyCreditPayRefund error", e);
        }

        log.info("PinganCreditPayReconcileJob.execute end. costTime:{}ms", System.currentTimeMillis() - begin);
    }

}
